package com.ruoyi.project.data.tradeOperate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.data.tradeOperate.domain.PaeaDsTradeExport;
import com.ruoyi.project.data.tradeOperate.domain.PaeaDsTradeQuery;
import com.ruoyi.project.paea.paeaDsTrade.domain.PaeaDsTrade;
import com.ruoyi.project.paea.paeaDsTrade.service.IPaeaDsTradeService;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.tool.DateTimeUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 交易流水Controller
 *
 * @author 魏刚
 * @date 2020-03-17
 */
@Controller
@RequestMapping("/data/tradeOperate")
public class TradeFilterController extends BaseController
{
    private String prefix = "data/tradeOperate";

    @Autowired
    private IPaeaDsTradeService paeaDsTradeService;

    @RequiresPermissions("data:tradeOperate:view")
    @GetMapping()
    public String paeaDsTrade()
    {
        return prefix + "/tradeFilter";
    }

    /**
     * 查询交易流水列表
     */
    @RequiresPermissions("data:tradeOperate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaDsTradeQuery paeaDsTradeQuery)
    {
        startPage();
        List<PaeaDsTrade> list = paeaDsTradeService.selectPaeaDsTrades(paeaDsTradeQuery);
        return getDataTable(list);
    }

    /**
     * 导出交易流水列表
     */
    @RequiresPermissions("data:tradeOperate:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaDsTradeQuery paeaDsTrade)
    {
        List<PaeaDsTrade> list = paeaDsTradeService.selectPaeaDsTrades(paeaDsTrade);
        List<PaeaDsTradeExport> listExport = new ArrayList<PaeaDsTradeExport>();
        for(PaeaDsTrade trade:list){
            PaeaDsTradeExport export = new PaeaDsTradeExport();
            BeanUtils.copyProperties(trade,export);
            listExport.add(export);
        }
        ExcelUtil<PaeaDsTradeExport> util = new ExcelUtil<PaeaDsTradeExport>(PaeaDsTradeExport.class);
        return util.exportExcel(listExport, "paeaDsTrade");
    }
    /**
     * 修改保存交易流水
     */
    @RequiresPermissions("data:tradeOperate:filterTrade")
    @Log(title = "交易流水", businessType = BusinessType.UPDATE)
    @PostMapping("/filterTrade")
    @ResponseBody
    public AjaxResult filterTrade(String  ids)
    {
        return toAjax(paeaDsTradeService.filterTradesByIds(ids));
    }

    /**
     * 删除交易流水
     */
    @RequiresPermissions("data:tradeOperate:openTrade")
    @Log(title = "交易流水", businessType = BusinessType.UPDATE)
    @PostMapping( "/openTrade")
    @ResponseBody
    public AjaxResult openTrade(String  ids){
        return toAjax(paeaDsTradeService.openTradesByIds(ids));
    }
}
